import React from 'react';
import PropTypes from 'prop-types';
import {Button} from 'antd';
import {formatMessage, injectIntl} from './intl';
import routes from './routes';
import {importTemp} from './api';
import ExcelImportIntl from '../common/ExcelImportIntl';

const basePath = fetch.basePath || '';

class ImportPanel extends React.PureComponent {
    afterUpload = file => {
        if(file.ok)
            this.props.onCancel();
    }
    
    render() {
        return (
            <div>
                <ExcelImportIntl
                    action={`${basePath}/afterSales/api/v1/vehicleSolds/import`}
                    template={importTemp}
                    templateName={formatMessage({
                        id: 'importPanel.show.importVehicleSold',
                        defaultMessage: '售后车辆导入模板'
                    })}
                    afterUpload={this.afterUpload} />
                <div className="page-toolbar">
                    <Button type="primary" onClick={this.props.onCancel}>{formatMessage({
                        id: 'importPanel.btn.return',
                        defaultMessage: '返回',
                    })}</Button>
                </div>
            </div>
        );
    }
}

ImportPanel.propTypes = {
    history: PropTypes.object,
    onCancel: PropTypes.func,
};
import {connect} from 'react-redux';

const mapDispatchToProps = (dispatch, props) => ({
    onCancel: () => {
        props.history.push(routes.query.url());
    }
});
export default connect(null, mapDispatchToProps)(injectIntl(ImportPanel));
